unit mainform;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    mmo1: TMemo;
    tmr1: TTimer;
    img1: TImage;
    procedure tmr1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

function GetCurrentCursorHandle: HCURSOR;
var
  pt: TPoint;
  h:HWND;
  dwThreadId, dwCurThreadId: DWORD;
  hc: HCursor;
begin
  hc := 0;

  if not GetCursorPos(pt) then Exit(0);

  h := WindowFromPoint(pt);

  dwThreadId := GetWindowThreadProcessId(h, nil);
  dwCurThreadId := GetCurrentThreadId;

  if (dwThreadId = dwCurThreadId) then
  begin
    Result := GetCursor;
  end
  else
  begin
    if AttachThreadInput(dwThreadId, dwCurThreadId, True) then
    begin
      Result := GetCursor;
      AttachThreadInput(dwCurThreadId, dwThreadId, False)
    end;

  end;
end;

procedure TForm2.tmr1Timer(Sender: TObject);
var
  h: HCURSOR;
begin
  h := GetCurrentCursorHandle;
  mmo1.Text := IntToStr(h);

  img1.Canvas.FillRect(img1.ClientRect);
  DrawIcon(img1.Canvas.Handle, 0, 0, h);
  img1.Refresh;


end;

end.
